<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>列表</title>
    <script type="text/javascript" src="../static/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript">

         function del(id){
             $.ajax({
                 type:"POST",
                 url:"/del",
                 data:{id:id},
                 dataType:"text",
                 success:function(msg){
                     alert(msg)

                     window.location.href="http://localhost:8888/list"
                 }

             })

         }

         function addOne(){

             var form= $("#add").serialize();

             $.ajax({
                 type:"POST",
                 url:"add?"+form,
                 dataType:"text",
                 success:function(msg){
                     alert(msg)
                     window.location.href="http://localhost:8888/list"
                 }

             })

         }


         function updateOne(id){

             $.ajax({
                 type:"POST",
                 url:"getOne?id="+id,
                 dataType:"json",
                 success:function(msg){
                    var uu= eval(msg);

                    $("#id1").val(uu.id);
                    $("#userName1").val(uu.userName);
                 }

             })

         }

    </script>
</head>
<body>

      <table>
          <#list dataList as data>
          <tr>
              <td>${data.id?string}</td>
              <td>${data.userName}</td>
              <td>
                  <input type="button" onclick="del(${data.id})">
                  <input type="button" onclick="updateOne(${data.id})" value="更新">
              </td>
          </tr>
         </#list>
      </table>


      <button onclick="addOne()">新增</button>

      <form action="" id="add" >

          <input name="userName" value="">

      </form>


      <h1>更新============</h1>

      <form action="update" id="update" >

          <input id="id1" name="id" type="hidden" value="">

          <input id="userName1" name="userName" value="">

          <input type="submit" value="提交">

      </form>

</body>
</html>